package Ptolemaiosz;

import java.awt.*;
import java.util.ArrayList;

public class LevelPartGraphicalEntity
{
	private ArrayList<GraphicalElement> graphicalElements = new ArrayList<GraphicalElement>();
	private LevelPart levelPart;
	private ArrayList<Integer> viewPort;
        private ArrayList<AvatarGraphicalEntity> avatars = new ArrayList<AvatarGraphicalEntity>();

        public void setAvatars(ArrayList<Avatar> elements)
            {
                for(int i = 1; i < elements.size(); i++)
                    {
                        GraphicalElement graphycalelement = elements.get(i).getGraphicalElement();
                        graphycalelement.setPhysicalEntity(elements.get(i).getPhysicalEntity());
                        graphycalelement.setLevelPartGraphicalEntity(this);
                    
                        avatars.add((AvatarGraphicalEntity)graphycalelement);
                    }
            }
        
	protected void draw(Graphics graphics)
            {
                //Megfelelo kasztolas, valamiert kell
                Graphics2D g2 = (Graphics2D)graphics;
                
                    //Hatter kirajzolasa                
                    g2.drawImage(TextureManager.getTexture("levelPart"), viewPort.get(0), viewPort.get(1), viewPort.get(2), viewPort.get(3), null);
         
                //elemek kirajzolasa
                for(int i = 0; i < graphicalElements.size(); i++)
                    {
                        graphicalElements.get(i).draw(graphics);
                    }
                
                //avatarok kirajzolasa
                for(int i = 0; i < avatars.size();i++)
                    {
                        //ha ezen a levelparton van, akkor kirajzoljuk
                        if(avatars.get(i).getLevelPart() == levelPart)
                            avatars.get(i).draw(graphics);
                    }
            }

	public void setLevelPart(LevelPart levelPart)
            {
              //attributum beallitasa
              this.levelPart = levelPart;
              
              //Elemmentek lekerese
              ArrayList<Element> elements = levelPart.getElements();
              
              for(int i = 0; i < elements.size(); i++)
                {
                    GraphicalElement graphycalelement = elements.get(i).getGraphicalElement();
                    graphycalelement.setPhysicalEntity(elements.get(i).getPhysicalEntity());
                    graphycalelement.setLevelPartGraphicalEntity(this);
                    
                    graphicalElements.add(graphycalelement);                            
                }
              
              //Avatarok lekerese
              //Honnan kerjuk le vazze?
              
            }
                
                
         

	public ArrayList<Integer> getViewPort() {
		return viewPort;
	}

	public void setViewPort(ArrayList<Integer> viewPort) {
		this.viewPort = viewPort;
	}
}